package com.akcome.apollo.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.akcome.apollo.common.TokenHelper;
import com.akcome.apollo.domain.BmpAccountWallet;
import com.akcome.apollo.service.BmpAccountWalletService;
import com.alibaba.fastjson.JSON;

/**
 * 校验
 * @author wn
 *
 */
@Controller
@RequestMapping("/validate")
public class ValidateController {

	
	@Autowired
	private TokenHelper tokenHelper;
	
	@Autowired
	private BmpAccountWalletService bmpAccountWalletService;
	
	/**
	 * 添加或更新钱包地址
	 * @param token
	 * @return
	 */
	@RequestMapping("/addwalletAddr")
	public String addwalletAddr(String token,ModelMap modelMap){
		String text = tokenHelper.getTextFromToken(token);
		if(StringUtils.isNotBlank(text)){
			BmpAccountWallet bmpAccountWallet = JSON.parseObject(text, BmpAccountWallet.class);
			bmpAccountWalletService.submitWalletAddr(bmpAccountWallet);
		}else{
			modelMap.put("fail", true);
		}
		return "validateResult";
	}
}
